package org.sun.web.util;

import java.util.HashMap;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;


@SuppressWarnings("unchecked")
public class DataUtil {

	
	public static <K,V> Map<K,V> toMap(Object...kv){
		Map<K,V> map=new HashMap<K,V>();
		for(int i=0;i<kv.length;i+=2){
			map.put((K)kv[i], (V)kv[i+1]);
		}
		return map;
	}
	
	public static String toJson(Object o){
		Gson gson=new Gson();
		return gson.toJson(o);
	}
	
	public static String toJsonWithoutExpose(Object o){
		Gson gson=new Gson();
		GsonBuilder gsonBuilder=new GsonBuilder();
		gsonBuilder.excludeFieldsWithoutExposeAnnotation();
		gson=gsonBuilder.create();
		return gson.toJson(o);
	}
}
